/*

  A mesh for a game. Contains geometry, material, and
  texture information.

  @author Richard Kelley, Liesl Wigand

 */

#ifndef MESH_H
#define MESH_H

/*object for storing meshes for object files: may not be needed with ASSIMP*/

#include <string>                       //
#include <vector>                       //
#include "vertex.h"                     //
#include <QtGui>                        //

typedef int* polygonFace;               //polygon faces are int pointers

namespace blackjack {

  class Mesh {
  private:
    std::string mtllib;                    //apparently this is never used, I'll remove it when I'm sure

    std::vector<Vertex*> *vertices;        //points in mesh
    std::vector<Vertex*> *textureCoords;   //texture coordinates: how to atatch the texture to the mesh
    std::vector<Vertex*> *vertexNormals;   //normals used for lighting and shading

    std::vector<polygonFace> *faces;       //faces formed by vertices

    bool useSmooth;                        //smooth or not

  public:
    float color[3];                        //the color to render in
    // accessor functions
    std::vector<polygonFace> *getFaces() { return faces; }      //
    std::vector<Vertex*> *getVertices() { return vertices; }    //

    // constructor
    Mesh() {
      vertices = new std::vector<Vertex*>();           //dynamic memory allocation
      textureCoords = new std::vector<Vertex*>();      //vectors of vertex pointers
      vertexNormals = new std::vector<Vertex*>();      //
      faces = new std::vector<polygonFace>();          //vectors of int pointers

    }

    // destructor
    ~Mesh() {
      delete vertices;                     //deallocation
      delete textureCoords;
      delete vertexNormals;
      delete faces;
    }

    /*
     draws this mesh
     */
    void draw();

    /*
      Add a vertex to this mesh. Check for membership of the vertex in
      the mesh. If the vertex is already in the mesh, don't do
      anything.
    */
    void addVertex(Vertex *v);

    /*
      Add a vertex normal to this mesh. Check for membership of the vn
      in the mesh. If the vn is already in the mesh, don't do anything.
     */
    void addVertexNormal(Vertex *v);

    /*
      Add a face to this mesh. If the vertices of the face are not in
      the mesh already, add them.

      Faces are assumed to be triangles and should be given in a
      counterclockwise orientation. By default this method checks that
      the given face is properly oriented, and will fail if the
      orientation test fails. If you know that your mesh format uses
      the proper orientation, you can disable checking to speed
      loading.
    */
    void addFace(polygonFace f, bool checkOrientation = true);

    /*
      Set whether or not we use smooth shading using smoothing groups.
     */
    void setSmooth(bool u);

    /*
      Return a string representation of this mesh.
     */
    std::string toString();

  };

}


#endif // MESH_H
